package com.ruoyi.reunion.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.reunion.domain.Notification;
import com.ruoyi.reunion.service.INotificationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.reunion.domain.ActivityParticipant;
import com.ruoyi.reunion.service.IActivityParticipantService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动参与人员Controller
 * 
 * @author ccccc
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/reunion/participant")
public class ActivityParticipantController extends BaseController
{
    @Autowired
    private IActivityParticipantService activityParticipantService;

    /**
     * 查询活动参与人员列表
     */
    @PreAuthorize("@ss.hasPermi('reunion:participant:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityParticipant activityParticipant)
    {
        startPage();
        List<ActivityParticipant> list = activityParticipantService.selectActivityParticipantList(activityParticipant);
        return getDataTable(list);
    }

    /**
     * 导出活动参与人员列表
     */
    @PreAuthorize("@ss.hasPermi('reunion:participant:export')")
    @Log(title = "活动参与人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityParticipant activityParticipant)
    {
        List<ActivityParticipant> list = activityParticipantService.selectActivityParticipantList(activityParticipant);
        ExcelUtil<ActivityParticipant> util = new ExcelUtil<ActivityParticipant>(ActivityParticipant.class);
        util.exportExcel(response, list, "活动参与人员数据");
    }

    /**
     * 获取活动参与人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('reunion:participant:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(activityParticipantService.selectActivityParticipantById(id));
    }

    /**
     * 新增活动参与人员
     */
    @PreAuthorize("@ss.hasPermi('reunion:participant:add')")
    @Log(title = "活动参与人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityParticipant activityParticipant)
    {
        return toAjax(activityParticipantService.insertActivityParticipant(activityParticipant));
    }

    @Autowired
    private INotificationService notificationService;
    @Log(title = "活动参与人员", businessType = BusinessType.UPDATE)
    @PutMapping("/approveParticipant")
    public AjaxResult approveParticipant(@RequestBody ActivityParticipant activityParticipant)
    {
        int i = activityParticipantService.updateActivityParticipant(activityParticipant);
        if (i == 0)
        {
            return AjaxResult.error("活动参与人员不存在");
        }else {
            ActivityParticipant activityParticipant1 = activityParticipantService.selectActivityParticipantById(activityParticipant.getId());
            Notification notification = new Notification();
            notification.setType(2L);
            notification.setContent("活动审核通过!");
            notification.setTargetId(activityParticipant1.getUserId());
            notification.setTitle("活动审核通知");
            notification.setCreateTime(new Date());
            notificationService.insertNotification(notification);
            return toAjax(i);
        }
    }
    /**
     * 修改活动参与人员
     */
    @PreAuthorize("@ss.hasPermi('reunion:participant:edit')")
    @Log(title = "活动参与人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityParticipant activityParticipant)
    {
        return toAjax(activityParticipantService.updateActivityParticipant(activityParticipant));
    }

    /**
     * 删除活动参与人员
     */
    @PreAuthorize("@ss.hasPermi('reunion:participant:remove')")
    @Log(title = "活动参与人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(activityParticipantService.deleteActivityParticipantByIds(ids));
    }
}
